package com.ruoyi.common.annotation;

import com.ruoyi.common.utils.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author：coderChen
 * @Package：com.ruoyi.common.annotation
 * @Project：RuoYi-Vue - 副本
 * @Date：2023/11/24 12:44
 * @Filename：NotNumberValidator
 */
public class NotNumberValidator implements ConstraintValidator<NotNumber, String>
{
    private  final String PATTERN = "^[0-9]*$";

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext)
    {
        if(StringUtils.isBlank(value)){
            return false;
        }
        return !containsHtml(value);
    }

    public  boolean containsHtml(String value)
    {
        Pattern pattern = Pattern.compile(PATTERN);
        Matcher matcher = pattern.matcher(value);
        return matcher.matches();
    }
}
